package com.cloud.xtools.api.interceptor;

import com.cloud.xtools.common.util.Auth;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.stereotype.Component;

@Component
public class OpenFeignInterceptor implements RequestInterceptor {

    @Override
    public void apply(RequestTemplate template) {
        System.out.println("OpenFeignInterceptor-拦截器");
        // System.out.println(Auth.getUsername());
        // 将用户信息添加到请求头中
        template.header("username", Auth.getUsername());
        if (Auth.getUserId() != null) {
            template.header("user-id", Auth.getUserId().toString());
        }
        template.header("permissions", Auth.getRequest().getAttribute("permissions").toString());
    }
}
